Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds docker-build command #313

Merged
merged 5 commits into from
Nov 20, 2017
Merged

Adds docker-build command #313

merged 5 commits into from
Nov 20, 2017

Conversation

olizilla
Copy link
Member

@olizilla olizilla commented Nov 17, 2017

Provides a "quick" way to compare the build output on "another" os.

I'm trying to find a minimal way to use docker as a builder; to have a single command that installs the deps and runs the build in a container, and then ejects the final build artefact.

This PR adds an npm run script called docker-build

"docker-build": "docker run -it --rm --name ipfs-companion-build -v \"$PWD\":/src -w /src node:8.9.1 /bin/bash -c \"npm install && npm run build\""

that'll spin up a node:8.9.1 debian jessie based docker container. It runs npm install && npm run build in the container. The project dir on the host is mounted as a volume into the container, so the zip file is written to the build dir on the host machine, just as if the build had been run locally.

There are some trade offs. It's simple to run, but the isolation is lower than you'd normally expect from a docker build. This means that your local node_modules dir will contain linux specific modules after running it, so you need to run a local npm rebuild to flip them back to your host os flavour. By being more selective with the mount config, we could probably avoid that, but i wanted to share this as is, to see if it's a reasonable idea.

The more dockery way would be to add a Dockerfile to the project. The process to get a bundle would then be

# create the image
docker build -t ipfs-companion .

# spin up the image `ipfs-companion` as a container process called `ipfs-companion-builder`
docker create --name ipfs-companion-builder ipfs-companion

meanwhile... in another shell

# Copy the zip from the container to your local machine.
docker cp ipfs-companion-builder:/src/build/ipfs_companion-2.0.15.zip ./build

Which seems way more cumbersome and manual...

Provides a "quick" way to compare the build output on "another" os
@olizilla
Copy link
Member Author

olizilla commented Nov 17, 2017

As always, writing up the PR notes has helped me think this through.

The npm run docker-build command is cool, but the pro solution to this is to have a Dockerfile that is used to build the image during CI for a release.

On a successful build the CI process would be configured to publish the image to the public docker registry along with the steps to run the container, extract the zip and and publish it to the various browser add-on registries. That'd be rad.

@lidel
Copy link
Member

lidel commented Nov 17, 2017

Really cool!

I think the issue of polluting host's node_modules can be solved by overriding it inside of a container with another (nested) volume.

Quick PoC:

> mkdir -p node_modules_docker
> docker run -it --rm --name ipfs-companion-build -v "$PWD":/src -v "$PWD"/node_modules_docker:/src/node_modules -w /src node:8.9.1 /bin/bash -c "npm install && npm run build"
> du -sh node_modules*
218M    node_modules
218M    node_modules_docker

We don't really care about node_modules_docker, it can be removed after the build.

Just for fun, another PoC, where node_modules does not leave docker and is kept in ephemeral 300MB RAM-disk:

> docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=300m,uid=1000 node_modules_tmpfs
> docker run -it --rm --name ipfs-companion-build -v "$PWD":/src -v node_modules_tmpfs:/src/node_modules -w /src node:8.9.1 /bin/bash -c "npm install && npm run build"
> docker volume rm node_modules_tmpfs 

@olizilla olizilla mentioned this pull request Nov 20, 2017
@lidel
Copy link
Member

lidel commented Nov 20, 2017

@olizilla Now that #311 is merged, I feel npm run docker-build may be enough for Mozilla.
Perhaps we could merge this and add a Dockerfile in separate PR?

@olizilla
Copy link
Member Author

i'll flip this pr to use the yarn.lock instead

@olizilla olizilla changed the title [WIP] Adds docker-build command Adds docker-build command Nov 20, 2017
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@lidel lidel merged commit 3f010d8 into master Nov 20, 2017
@lidel lidel deleted the docker-build branch November 20, 2017 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants